<template>
  <div class="add-edit">
      <el-form ref="form" :model="formDialog" label-width="80px">
        <el-form-item label="角色名称" prop="name">
          <el-input v-model="formDialog.name"></el-input>
        </el-form-item>
        <el-form-item label="角色编码" prop="code">
          <el-input v-model="formDialog.code"></el-input>
        </el-form-item>
        <el-form-item label="角色描述" prop="description">
          <el-input type="textarea" v-model="formDialog.description"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleDialogSubmit">确 定</el-button>
      </span>
  </div>
</template>
<script>
import { getSaveOrUpdate, getRoleEdit } from '@/services/role'
export default {
  name: 'add-edit',
  props: {
    roleId: {
      type: [Number, String]
    }
  },
  data () {
    return {
      formDialog: {
        name: '',
        code: '',
        description: ''
      }
    }
  },
  created () {
    this.loadRolesEdit()
  },
  methods: {
    async loadRolesEdit () {
      const { data } = await getRoleEdit(this.roleId)
      if (data.code === '000000') {
        this.formDialog = data.data
      }
    },
    async handleDialogSubmit () {
      const { data } = await getSaveOrUpdate(this.formDialog)
      if (data.code === '000000') {
        this.dialogVisible = false
        this.formDialog = {}
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
